package org.anderground.internal.graphics.impl;

import org.anderground.core.graphics.PathEffect;
import org.anderground.core.graphics.Shader;
import org.anderground.internal.graphics.abstaractions.AbstractPaint;

import android.graphics.Paint;

public class AndroidPaint implements AbstractPaint {

	public static Paint cast(org.anderground.core.graphics.Paint aPaint) {
		return ((AndroidPaint) (aPaint.getDelegate())).getPaint();
	}

	private Paint paint;

	public AndroidPaint(Paint paint) {
		this.paint = paint;
	}

	public int getColor() {
		return paint.getColor();
	}

	public PathEffect getPathEffect() {
		return AndroidPathEffect.castBack(paint.getPathEffect());
	}

	public Shader getShader() {
		return AndroidShader.castBack(paint.getShader());
	}

	public Cap getStrokeCap() {
		return AndroidCap.castBack(paint.getStrokeCap());
	}

	public float getStrokeWidth() {
		return paint.getStrokeWidth();
	}

	public Style getStyle() {
		return AndroidStyle.castBack(paint.getStyle());
	}

	public float getTextSize() {
		return paint.getTextSize();
	}

	public boolean isAntiAlias() {
		return paint.isAntiAlias();
	}

	public float measureText(String text) {
		return paint.measureText(text);
	}

	public void setAlpha(int a) {
		paint.setAlpha(a);
	}

	public void setAntiAlias(boolean aa) {
		paint.setAntiAlias(aa);
	}

	public void setARGB(int a, int r, int g, int b) {
		paint.setARGB(a, r, g, b);
	}

	public void setColor(int color) {
		paint.setColor(color);
	}

	public PathEffect setPathEffect(PathEffect effect) {
		return AndroidPathEffect.castBack(paint.setPathEffect(AndroidPathEffect
				.cast(effect)));
	}

	public void setShader(Shader shader) {
		paint.setShader(AndroidShader.cast(shader));
	}

	public void setStrokeCap(Cap cap) {
		paint.setStrokeCap(AndroidCap.cast(cap));
	}

	public void setStrokeWidth(float width) {
		paint.setStrokeWidth(width);
	}

	public void setStyle(Style style) {
		paint.setStyle(AndroidStyle.cast(style));
	}

	public void setTextSize(float textSize) {
		paint.setTextSize(textSize);
	}

	public Paint getPaint() {
		return paint;
	}

	private static class AndroidCap {

		public static android.graphics.Paint.Cap cast(Cap aCap) {

			if (aCap == Cap.SQUARE) {
				return android.graphics.Paint.Cap.SQUARE;
			} else if (aCap == Cap.ROUND) {
				return android.graphics.Paint.Cap.ROUND;
			} else {
				return android.graphics.Paint.Cap.BUTT;
			}
		}

		public static Cap castBack(android.graphics.Paint.Cap cap) {

			if (cap == android.graphics.Paint.Cap.SQUARE) {
				return Cap.SQUARE;
			} else if (cap == android.graphics.Paint.Cap.ROUND) {
				return Cap.ROUND;
			} else {
				return Cap.BUTT;
			}
		}

	}

	private static class AndroidStyle {

		public static android.graphics.Paint.Style cast(Style aStyle) {

			if (aStyle == Style.STROKE) {
				return android.graphics.Paint.Style.STROKE;
			} else if (aStyle == Style.FILL_AND_STROKE) {
				return android.graphics.Paint.Style.FILL_AND_STROKE;
			} else {
				return android.graphics.Paint.Style.FILL;
			}
		}

		public static Style castBack(android.graphics.Paint.Style aStyle) {

			if (aStyle == android.graphics.Paint.Style.STROKE) {
				return Style.STROKE;
			} else if (aStyle == android.graphics.Paint.Style.FILL_AND_STROKE) {
				return Style.FILL_AND_STROKE;
			} else {
				return Style.FILL;
			}
		}

	}

}
